﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 考核一
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }
        OleDbConnection oc = new OleDbConnection();
        string str=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\C#\考核一\考核一.mdb";
        

        private void button1_Click(object sender, EventArgs e)
        {
            oc.ConnectionString = str;
            oc.Open();
            DataSet ds = new DataSet();
            string str1 = "select * from zym";
            OleDbDataAdapter oda = new OleDbDataAdapter(str1, oc);
            oda.Fill(ds, "zym");
            dataGridView1.DataSource = ds.Tables["zym"];
            oc.Close();
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string str2 = this.dataGridView1.SelectedCells[1].Value.ToString();
            oc.ConnectionString = str;
            oc.Open();
            OleDbCommand ocm = new OleDbCommand();
            ocm.Connection = oc;
            ocm.CommandText = "delete from zym where 用户名 = '" + str2+"'";
            ocm.ExecuteNonQuery();
            dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
        }
    }
}
